package Demo6;

import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        Student student1=new Student("afei",9);
        Student student2=new Student("zili",19);
        Student student3=new Student("lidas",6);
        Student[] student=new Student[3];
        student[0]=student1;
        student[1]=student2;
        student[2]=student3;
        nameCompare comparator2=new nameCompare();
        System.out.println(Arrays.toString(student));
        //Arrays.sort(student);
        Arrays.sort(student,comparator2);
        System.out.println(Arrays.toString(student));
    }

    public static void main6(String[] args) {
        Student student1=new Student("afei",9);
        Student student2=new Student("lili",19);
        Student student3=new Student("lidas",6);
        Student[] student=new Student[3];
        student[0]=student1;
        student[1]=student2;
        student[2]=student3;
        ageCompare comparator1=new ageCompare();
        System.out.println(Arrays.toString(student));
        //Arrays.sort(student);
        Arrays.sort(student,comparator1);
        System.out.println(Arrays.toString(student));
    }

    public static void main5(String[] args) {
        Student student1=new Student("zfei",9);
        Student student2=new Student("lili",19);
        Student student3=new Student("lidas",6);
        System.out.println("根据年龄进行比较");
        ageCompare comparator1=new ageCompare();
        int ret=comparator1.compare(student1,student2);
        //int ret=student1.compareTo(student2);
        if(ret>0){
            System.out.println("student1>student2");
        }
        else if(ret==0){
            System.out.println("student1==student2");
        }
        else{
            System.out.println("student1<student2");
        }

        System.out.println("根据姓名进行比较：");
        nameCompare comparator2=new nameCompare();
        ret=comparator2.compare(student1,student2);

        //int ret=student1.compareTo(student2);
        if(ret>0){
            System.out.println("student1>student2");
        }
        else if(ret==0){
            System.out.println("student1==student2");
        }
        else{
            System.out.println("student1<student2");
        }
    }
    /*public static void bubbleSort(Comparable[] comparables){
        for(int i=0;i<comparables.length;i++){
            for(int j=0;j<comparables.length-1-i;j++){
                if(comparables[j].compareTo(comparables[j+1])>0){
                    Comparable temp=comparables[j];
                    comparables[j]=comparables[j+1];
                    comparables[j+1]=temp;
                }
            }
        }
    }*/
    public static void main2(String[] args) {
        Student student1=new Student("afei",9);
        Student student2=new Student("lili",19);
        Student student3=new Student("lidas",6);
        Student[] student=new Student[3];
        student[0]=student1;
        student[1]=student2;
        student[2]=student3;
        System.out.println(Arrays.toString(student));
        //Arrays.sort(student);
        //bubbleSort(student);
        System.out.println(Arrays.toString(student));
    }
    public static void main1(String[] args) {
        Student student1=new Student("afei",9);
        Student student2=new Student("lili",19);
        Student student3=new Student("lidas",6);
        int ret=student1.compareTo(student2);
        if(ret>0){
            System.out.println("student1>student2");
        }
        else if(ret==0){
            System.out.println("student1==student2");
        }
        else{
            System.out.println("student1<student2");
        }
    }
}
